<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>营改增-发票 - 临时表 </title>

    <link rel="stylesheet" th:href="@{/static/iview/iview.css}">
    <script th:src="@{/static/libs/jquery-3.2.1.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/libs/vue.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/layer/layer.js}" type="text/javascript"></script>
   <script th:src="@{/static/iview/iview.min.js}" type="text/javascript"></script>
	<script th:src="@{/static/common.js}" type="text/javascript"></script>
    <style type="text/css">
	[v-cloak] {
			  display: none;
			}
	</style>
</head>
<body>
<div id="app" v-cloak>
        <div style="margin-bottom: 6px;margin: 30px">
			<i-input v-model="content"  placeholder="交易编号" id="gid"  style="width: 300px"></i-input>
			<i-select  v-model="transtype"  style="width: 150px" @on-change="changtranstypelist">
		              <i-option v-for="item in transtypelist"  :value="item.id"  :key="item.value">{{item.value}} </i-option>
		     </i-select> 
		     <!-- 处理结果 -->
		      <i-select  v-model="processresult"  style="width: 80px" @on-change="changprocessresultlist">
		              <i-option v-for="item in processresultlist"  :value="item.id"  :key="item.value">{{item.value}}</i-option>
		     </i-select> 
		     
		    <i-button type="primary" @click="search()" icon="ios-search">搜索</i-button>
			<i-button type="primary" @click="empty()" icon="ios-close-empty">清空</i-button>
			<i-button type="info" style="float: right;" @click="add()" icon="person-add">新增</i-button>
		</div>
		<div style="margin-bottom: 6px;margin: 30px">
			<template> 
				<i-table border :content="self" :columns="tableTitle" :data="datalist"></i-table>
			 	<br>
<!-- 			 	<Page :total="dataCount" :page-size="pageSize" show-total @on-change="changepage" @on-page-size-change="changePageSize"></Page> -->
			 	<!--分页功能-->
				<Page :current="1" :total="dataCount" :page-size="pageSize"  @on-change="changepage"  @on-page-size-change="changePageSize" show-elevator show-sizer show-total></Page>
				 
			</template>
		</div>
</div>
<script type="text/javascript">
var vm = new Vue({
	el : '#app',
	data : {
		content : '',
		pageNo : 1,
		pageSize : 10,// 每页显示多少条
		dataCount:"", // 总数据的条目
		datalist: [], //接口获取的总数据
		historyData:'',//展示的数据 
		transtype:'',
	    transtypelist:[
	    	{"id":"1","value":"1 - 省内门架交易①"},
	    	{"id":"2","value":"2 - 省内刷卡交易"},
	    	{"id":"3","value":"3 - 省内门架交易②"},
	    	{"id":"4","value":"4 - 省内门架交易③"},
	    	{"id":"5","value":"5 - 省内门架交易④"},
	    	{"id":"12","value":"12 - 省内其他交易①"},
	    	{"id":"13","value":"13 - 省内其他交易②"}
	    ],
	    processresult:'',
	    processresultlist:[{"id":"-3","value":"效验错误"},{"id":"-2","value":"未发送"},{"id":"-1","value":"已发送"}],
		tableTitle:[
		{
			   title : "编号",
			   type: 'index',
			   align: 'center',
	            width: 70
	   },
		{
		    key : "mid",
			title : "交易标识号"
		}, 
		{
			key : "transTypeCode",
			title : "交易类型",
			render : function(h, params) {
				var text =params.row.transTypeCode;
				if(params.row.transTypeCode == 1 || params.row.transTypeCode == 3 || params.row.transTypeCode == 4 || params.row.transTypeCode == 5 ){ 
					text ="省内门架交易";
				}else if(params.row.transTypeCode == 2){
					text ="省内刷卡交易";
				}else if(params.row.transTypeCode == 12 || params.row.transTypeCode == 13){
					text ="省内其他交易";
				}
				return h('div',text);
			}
		},
		{
			key : "processResult",
			title : "处理结果",
			render : function(h, params) {
				var text = "不能识别（"+params.row.processResult +"）";
				if(params.row.processResult == -1){
					text = "已发送未反馈（-1）"
				}else if(params.row.processResult == -2){
					text = "未发送（-2）"
				}
				return h('div',text);
			}
		}, 
		{
			key : "fileName",
			title : "文件"
		},
		{
			key : "createTime",
			title : "创建时间",
			render : function(h, params) {
					if(params.row.createTime !=null){
						timer = formatDate(new Date(params.row.createTime),'yyyy-MM-dd hh:mm:ss');
					}
				    return h('div',timer);
		    }
		},
		{
			title : '操作',
			key : 'action',
			width : 170,
			align : 'left',
			render : function(h, params) {
				var functionList = [];
				//修改
				var edit = h('Button', {
					props : {
						type : 'primary',
						size : 'small',
						icon : 'edit'
					},
					style : {
						marginRight : '8px'
					},
					on : {
						click : function() {
							vm.edit(params.row);
						}
					}
				}, '修改');
				functionList.push(edit);
				//移除
				var remove = h('Button', {
					props : {
						type : 'primary',
						size : 'small',
						icon : 'close'
					},
					style : {
						marginRight : '8px'
					},
					on : {
						click : function() {
							vm.remove(params.row.mid,params.row.transTypeCode);
						}
					}
				}, '移除');
				functionList.push(remove);
				// 返回方法集合
				return h('div', functionList);
			}
		}]
		
	},
	methods : {
		search : function(){
			this.loadlist(1);
		},
		empty : function(){
			vm.content = '';
			vm.transtype='';
			vm.multiprovince='';
			vm.processresult='';
			this.loadlist(1);
		},
		loadlist : function(index) {
			var page = {};
			page['pageIndex']= index ;
			page['pageSize']= this.pageSize;
					
			var params = {};
			if(this.content !=''){
				params['gid']=this.content;
				if(!isNaN(this.content)){
					params['issuerId'] =this.content;
				}
				//params['mid']=this.content;
				
			}
			
			if(this.multiprovince!=''){
				params['multiProvince'] =  parseInt(this.multiprovince);
			}
			
			if(this.processresult !=''){
				params['processResult'] =  parseInt(this.processresult);
			}
			
			if(!isNaN(this.transtype)){
				params['transTypeCode'] =  parseInt(this.transtype);
			}
			var conditional = {};
			conditional['page'] = page;
			conditional['params'] = params;
		   //json格式转换
			var json =  JSON.stringify(conditional);
			
			$.ajax({
				url:"../bill/getBillList",
				type:"post",
				data: json,
				dataType: "json",
				contentType: 'application/json', 
				success: function(data) {
					vm.datalist = data.result.rows;
					vm.dataCount = data.result.total; //接口返回数据的总条目数
					
					if(vm.dataCount < vm.pageSize){   //如果数据的总条目数小于每页显示的条目数就赋值，否则就提取总数据的第三条
                        vm.historyData   = vm.JobData
                    }else{
                        vm.historyData = vm.datalist.slice(0,self.pageSize);
                    }
				}
			});
		},
		 //页数变化的时候改变每一页的内容
        changepage(index){
			this.loadlist(index);
        },
        //修改每页显示条数时调用
        changePageSize(num) { 
           this.pageSize = num;
           this.changepage(1);
       },
       changtranstypelist:function(value){
    	   vm.transtype=value;
       },
       changmultiprovincelist:function(value){
    	   vm.multiprovince=value;
       },
       changprocessresultlist:function(value){
    	   vm.processresult=value;
       },
      /*  transtypedroplist:function(){
    		$.ajax({
				url:"../monitor/loadTransTypeCodeDropList",
				type:"get",
				contentType: 'application/json', 
				success: function(data) {
						if(data.result != null){
							vm.transtypelist = data.result;
						}
				}
			});
       }, */
		edit : function(data){
			//构造请求参数
			var params = {};
			params['mid']=String(data.mid);
			params['transTypeCode']=data.transTypeCode;
			var conditional = {};
			 conditional['params'] = params;
			 //JSON格式化
			var json =  JSON.stringify(conditional);
			//数据加载函数
			function loadByPrimaryKey(){
				$.ajax({
					url:"../monitor/getTransGantryEtc",
					type:"post",
					data: json,
					dataType: "json",
					contentType: 'application/json', 
					success: function(data) {
							if(data != null && data.result != null){
								console.warn("执行结果："+data.result);
							}
					}
				});
			}
        
			var gantry = {
					title:"ETC门架交易 (编辑)",
				    routerUrl:"/clear/editTransGantryEtc.shtml",
				    ajaxUrl:"../monitor/getTransGantryEtc",
				    transTypeCode : [1,3,4,5],
					style:{
						scroll : true,
						width: '80%',
						height: '80%'
					}
			};
			
			var transExit = {
					title:"出口车道交易 (编辑)",
				    routerUrl:"/clear/editTransExit.shtml",
				    ajaxUrl:"../monitor/getTransExit",
				    transTypeCode:[2,12,13],
					style:{
						scroll : true,
						width: '80%',
						height: '80%'
					}
			};
			
			
			var defaultValue = {
					title:"未知错误",
				    routerUrl:"/exception/unkown.shtml",
				    ajaxUrl:"",
				    transTypeCode : [],
					style:{
						scroll : true,
						width: '80%',
						height: '50%'
					}
			};
			
			var setup = null;
			var datas = [gantry,transExit];
			for(var i =0;i<datas.length;i++){
				if(datas[i].transTypeCode.indexOf(data.transTypeCode) !=-1){
					 setup = datas[i];
					 break ;
				}
			}

			if(setup == null){
				setup = defaultValue;
			}
			
			
			dialogOpen({
				title: setup.title,
				url: setup.routerUrl,
				scroll : setup.style.scroll,
				width:  setup.style.width,
				height: setup.style.height,
				success : function(iframeId){
					$.ajax({
						url:setup.ajaxUrl,
						type:"post",
						data: json,
						dataType: "json",
						contentType: 'application/json', 
						success: function(data) {
								top.frames[iframeId].vm.formProperty = data.result;
						}
					});
				},
				yes : function(iframeId) {
					top.frames[iframeId].vm.acceptClick();
				},
			});
		},
		//移除任务
		remove : function(mid,transtrype){
			var that = this;
			top.layer.confirm('确定要移除任务吗？', {
			      btn: ['确定','取消'] //按钮
			}, function(){
				var params = {};
				if(!isNaN(this.content)){
					params['mid']=parseInt(mid);
				}
				if(!isNaN(this.transtype)){
					params['transTypeCode'] =  parseInt(transtrype);
				}
				var conditional = {'params': params};
				
				$.ajax({
					url:"../monitor/removeClearTempData",
					type:"post",
					dataType: "json",
					contentType: 'application/json', 
					data:  JSON.stringify(conditional),
					success: function(result) {
						if(result.err_code=="200"){
							top.layer.msg('数据移除成功', {icon: 1});
							window.setTimeout(that.loadlist(1),1500); 
						}
					}
				});
			}, function(){
			  
			});
		}
	},
	created : function() {
		 this.loadlist(1);
         //this.changepage(0);
	}
})

</script>
</body>
</html>